<?php

// +----------------------------------------------------------------------
// | 文件 ApiStatisBehavior.class.php
// +----------------------------------------------------------------------
// | 说明 接口统计
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

namespace Common\Behavior;
use Think\Behavior;
use Think\Hook;

use Api\Event\CacheEvent;

defined('THINK_PATH') or exit();

class ApiStatisBehavior extends Behavior 
{

	public function run(&$param)
	{
		$ttl = 2*7*24*3600;   
		$redis = CacheEvent::instance(2);
		$week = date('YW');
		$key   = "IMBA.STATIS.ACTION.{$week}";
		if ($redis->exists($key)){
			$redis->zincrby($key, 1, $param['action']);
		}else{
			$redis->multi();
				$redis->zadd($key, 1, $param['action']);
				$redis->expire($key, $ttl);
			$redis->exec();
		}
		
	}

}